package com.bw.kotlindemo.kotlin.view.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.bw.kotlindemo.R
import com.bw.kotlindemo.databinding.ItemLiveListBinding
import com.bw.kotlindemo.java.model.bean.LiveListBean
import com.bw.kotlindemo.java.utils.ImgLoadUtils

/**
 * desc:kotlin列表
 * create by xushaodong on 2023/4/7
 */
class KLiveListAdapter(_context: Context) : RecyclerView.Adapter<KLiveListHolder>() {
    private val context = _context
    val data = mutableListOf<LiveListBean.ResultBean>()
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KLiveListHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_live_list, parent, false)
        return KLiveListHolder(view)
    }

    override fun onBindViewHolder(holder: KLiveListHolder, position: Int) {
        holder.binding?.let {
            val resultBean = data[position]
            it.tvTitle.text = resultBean.liveTitle
            ImgLoadUtils.loadImg(context,resultBean.liveCoverUrl,it.img)
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }

    fun setData(setData:List<LiveListBean.ResultBean>){
        data.clear()
        data.addAll(setData)
        notifyDataSetChanged()
    }
}

class KLiveListHolder(_item: View) : RecyclerView.ViewHolder(_item) {
    var binding = DataBindingUtil.bind<ItemLiveListBinding>(_item)
}